import { ReportDTO, ReportDetailDTO } from './../dto/report';
import {
  Inject,
  Controller,
  Post,
  Provide,
  Validate,
  Body,
  Query,
  ALL,
  Get,
} from '@midwayjs/decorator';
import { Context } from 'egg';
import BaseController from '../core/baseController';
import { ReportService } from '../service/report';

@Provide()
@Controller('/rrweb')
export class ReportController extends BaseController {
  @Inject()
  ctx: Context;

  @Inject()
  reportService: ReportService;

  @Post('/report')
  @Validate()
  async report(@Body(ALL) report: ReportDTO) {
    const id = await this.reportService.saveReport(report);
    return this.success(id);
  }

  @Get('/report')
  async reportList() {
    return this.success(await this.reportService.getReportList());
  }

  @Get('/report/detail')
  async reportDetail(@Query(ALL) { eventId }: ReportDetailDTO) {
    return this.success(await this.reportService.getReportDetail(eventId));
  }
}
